cmake_minimum_required(VERSION 3.5)
project(cv_detection_cpp)

# 设置C++标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找并设置ROS 2相关的包
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(origincar_msg REQUIRED)  # 确保你的自定义消息路径正确

# 查找并设置OpenCV
find_package(OpenCV REQUIRED)
find_package(cv_bridge REQUIRED)

# 查找并设置zbar
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBAR REQUIRED zbar)

# 包含目录
include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${rclcpp_INCLUDE_DIRS}
    ${sensor_msgs_INCLUDE_DIRS}
    ${origincar_msg_INCLUDE_DIRS}
    ${ZBAR_INCLUDE_DIRS}
)

# 添加可执行文件
add_executable(cv_detection_cpp src/cv_detection_cpp.cpp)  # 请根据实际路径调整

# 链接依赖库  
ament_target_dependencies(cv_detection_cpp   
  rclcpp  
  sensor_msgs 
  origincar_msg  
  OpenCV
  ZBAR
  cv_bridge
)  

# 链接库
target_link_libraries(cv_detection_cpp
    ${OpenCV_LIBS}
    rclcpp::rclcpp
    #sensor_msgs::sensor_msgs  # 使用正确的库名称
    #origincar_msg::origincar_msg  # 使用正确的库名称
    ${ZBAR_LIBRARIES}
    ${cv_bridge_LIBRARIES}
)

# 安装目标
install(TARGETS
    cv_detection_cpp
    DESTINATION lib/${PROJECT_NAME}
)

# 导出依赖项
ament_export_dependencies(rclcpp sensor_msgs origincar_msg OpenCV)

# 安装配置文件
ament_package()
